<template>
	<view>
		<!-- <index-bar-fixed title="预医管理助手" :bg="false"></index-bar-fixed> -->
		<view class="index">
			<view class="shoyetop">
				<view class="shoyetopmain">
					<view class="shoyetopl">
						<image src="../../static/img/shouyelogo.png" mode=""></image>
					</view>
					<view class="shoyetopr">
						{{topTips}}
					</view>
				</view>
			</view>
			<view class="docinfo" @click="isGoLogin">
				<view class="docinfomain">
					<view class="docinfomainl">
						<view class="doctop">
							{{info.nickName ? info.nickName : '已登录(待完善资料)'  }} <span
								class="zhicheng">{{zhichengName ? zhichengName : '' }}</span>
						</view>
						<view class="docbottom">
							{{info.corpName}}
						</view>
					</view>
					<view class="docinfomainr">
						<my-avatar :avatar="info.avatar" :nickName="info.nickName" :sex="info.sex"></my-avatar>
					</view>
				</view>
			</view>
			<roll-nav :nav="nav" @goContents="goContent"></roll-nav>
			<view class="job_box">
				<view class="job_nav">
					<view :class="{'black':navChoose == 0}" @click="goAction">
						待执行（{{zhixingNum}}）
					</view>
					<view class="m-l-40" :class="{'black':navChoose == 2}" @click="really">
						待评估（{{pingguNum}}）
					</view>
				</view>
				<view class="job_empty" v-if="emptyJob">
					<view class="">
						<u-image width="335rpx" height="320rpx" :src="actionImg"></u-image>
					</view>
					<view class="empty_text">
						{{emptyText}}
					</view>
				</view>

				<view class="job_content" v-if="!emptyJob">
					<view class="job_list" v-for="(v,n) in list">
						<view class="">
							<view class="">
								{{v.jobStartTime}}
							</view>
							<view class="job_title">
								<view class="job_title_icon" :class="{yellow:v.jobType == 2}">{{jobType(v.jobType)}}
								</view>
								<view class="">
									{{v.jobName}}
								</view>
							</view>
							<view class="" v-if="navChoose == 0">
								目标患者：{{v.targetCustomerNum}}人
							</view>
							<view class="" v-if="navChoose == 2">
								目标患者：{{v.targetCustomerName}}
							</view>
							<view class="">
								{{v.jobContent}}
							</view>
						</view>

						<view class="job_action">
							<view class="jobNav2" v-if="navChoose == 2" @click="goPinggu(v)">
								录入综合评估
							</view>
							<view class="job_left" @click="myAction(v)" v-if="navChoose == 0">
								立即执行
							</view>
							<view class="job_right" @click="overView(v)" v-if="navChoose == 0">
								忽略
							</view>
						</view>
					</view>
					<view style="padding-top: 40rpx;padding-bottom: 40rpx;">
						<u-loadmore :status="status" v-if="!empty" />
					</view>
				</view>
			</view>
		</view>
		<u-modal v-model="show" :show-title="false" :content="content"
			:content-style="{'fontSize':'32rpx','lineHeight': '1.5','fontWeight':'bold'}" cancel-color="#333333"
			:show-cancel-button="true" confirm-color="#4DC0D9" @confirm="confirm" @cancel="cancel"
			:cancel-style="{'borderRight':'1px solid #f8f8f8'}">
		</u-modal>
	</view>
</template>

<script>
	import {
		checkToken,
		checkAuth,
	} from '@/utils/index.js'
	import {
		getTeamByUser,
		getInfo,
		swTeam,
		indexJobList,
		executeOrIgnoreFollowupPlanJob,
		getIndexJobNum
	} from '@/api/index.js'
	import pageMixinNorRequest from '@/utils/pageMixinNorRequest.js'
	export default {
		mixins: [pageMixinNorRequest],
		data() {
			return {
				//topTips:'您还未登录，请登录后体验功能！',  //欢迎登录，如有问题请联系：0371-60957906
				isLogin: false,
				actionImg: require('@/static/img/No_follow.png'),
				emptyJob: false,
				emptyText: '暂无待执行随访任务',
				//	PreActionImg:require('@/static/img/No_team@2x.png'),
				info: {
					nickName: '未登录',
					corpName: '登录后方可体验功能',
					avatar: '',
					info: '',
					sex: '',
					avatar: require('@/static/img/Login_logo.png')
				},
				teamFlag: false,
				zhichengName: '', //职称
				nav: [{
						'src': require('@/static/img/home _my To-do list@2x.png'),
						'name': '我的待办',
						'opacity': false,
						'url': '/pages/index/project'
					},
					{
						'src': require('@/static/img/home_my order@2x.png'),
						'name': '我的订单',
						'opacity': false,
						'url': '/pages/index/order/index'
					},
					{
						'src': require('@/static/img/home_My consultation@2x.png'),
						'name': '我的咨询',
						'opacity': true,
						'url': ''
					},
					{
						'src': require('@/static/img/home_My reputation@2x.png'),
						'name': '我的口碑',
						'opacity': false,
						'url': '/pages/index/repulation/index'
					}
					// ,{
					// 	'src': require('@/static/icon/keshi_icon.png'),
					// 	'name': '科室管理',
					// 	'url': '/pages/index/tohcem'
					// }
				],
				show: false,
				content: '',
				navChoose: 0,
				currentObj: '', //当前选中的要执行对象
				zhixingNum: 0,
				pingguNum: 0
			}
		},
		computed: {
			topTips() {
				if (this.isLogin) {
					//return '欢迎登录，如有问题请联系：0371-60957906'
					return '欢迎登录您的数字医生工作室！'
				} else {
					return '您还未登录，请登录后体验功能！'
				}
			},
			jobType(type) {
				return (type) => type == 1 ? '定时' : '周期'
			}
		},
		mounted() {
			//this.getlist()
			//this.$on('userInfo', this.userInfo)


		},
		async onShow() {
			//await this.pingguList()
			await this.getNum()
			await this.userInfo()
			await this.gomyTeam()
			//setTimeout(()=>{
			this.clearPageStatus()
			this.getTeam()
			//},1500)
		},
		async onLoad() {
			//await this.getlist()
			uni.removeStorageSync('PINGGUDETAILS')
		},
		methods: {
			async getNum() {
				let res = await getIndexJobNum()
				if (res.code == 200) {
					this.zhixingNum = res.waitRun
					this.pingguNum = res.recordEvent
				}
				//console.log(res,'num');
			},
			async getMyList(obj) {
				// 例如， {..obj,id:15}
				let res = await indexJobList(this.navChoose, obj)
				let rows = res.rows.length
				if (this.navChoose == 0) {
					this.zhixingNum = res.total
				}
				if (this.navChoose == 2) {
					this.pingguNum = res.total
				}

				if (rows == 0) {
					this.emptyJob = true
				} else {
					this.emptyJob = false
				}
				// this.teamNumber = res.total //单独需要赋值的地方
				return res
			},
			async pingguList() { //为了获得待评估的条数
				if (this.navChoose == 0) {
					let res = await indexJobList(2, {
						pageNum: 1,
						pageSize: 15
					})
					this.pingguNum = res.total
				}
				if (this.navChoose == 2) {
					let res = await indexJobList(0, {
						pageNum: 1,
						pageSize: 15
					})
					this.zhixingNum = res.total
				}

			},
			async confirm() { //忽略
				let params = {
					executeOrIgnore: 'ignore',
					jobId: this.currentObj.id
				}
				let res = await executeOrIgnoreFollowupPlanJob(params)
				if (res.code == 200) {
					this.clearPageStatus()
					await this.getTeam()
				}
				// this.list.splice(n, 1)
				// console.log(123);
				// this.list = this.list.filter(v => v.ignore != true)
				// if (this.list.length == 0) this.emptyJob = true
			},
			cancel() {

			},
			async overView(obj) { //忽略
				this.currentObj = obj
				this.show = true //忽略弹窗
				this.content = `忽略后将不再对目标患者执行“${obj.jobName}”任务，确定要忽略该任务吗？`
			},
			async myAction(obj) { //执行
				let params = {
					executeOrIgnore: 'execute',
					jobId: obj.id
				}
				let res = await executeOrIgnoreFollowupPlanJob(params)
				if (res.code == 200) {
					uni.showLoading({
						title: "加载数据中"
					})
					setTimeout(async () => {
						uni.hideLoading()
						this.clearPageStatus()
						await this.getTeam()
					}, 3000)
				}
			},
			goPinggu(obj) { //评估
				//console.log(obj,'lll');
				//this.$store.commit('PINGGUDETAILS',obj)
				uni.setStorageSync('PINGGUDETAILS', obj)
				uni.navigateTo({
					url: '/pages/index/pinggu'
				})
			},
			async gomyTeam() {
				let r = uni.getStorageSync('myTeam')
				if (!r && r.code != 200) { //选过团队直接进
					let users = await getTeamByUser()
					if (users.code == 200) {
						if (users.rows.length > 0) {
							let findTeam = users.rows.find(v => v.chargePerson == this.info.nickName)
							//console.log(findTeam,'545');
							if (!findTeam) return
							let res = await swTeam(findTeam.id)
							if (res.code == 200) {
								uni.setStorageSync('myTeam', res)
							}
							//console.log(1111);
						}
					}
				}
			},
			isGoLogin() {
				if (!this.isLogin) {
					uni.redirectTo({
						url: '/pages/login/index'
					})
				}
			},
			async goContent(urlString) {
				console.log(urlString);
				//this.$u.toast('努力开发中，敬请期待！')
				//return
				//'/pages/login/index' 
				if (!checkToken()) return
				if (!checkAuth()) return
				if (urlString == '/pages/index/project') {  //我的待办
					uni.navigateTo({
						url: urlString
					})
					return
				}
				if (urlString == '/pages/index/order/index') {  //我的订单
					uni.navigateTo({
						url: urlString
					})
					return
				}
				if (urlString == '/pages/index/repulation/index') {  //我的口碑
					uni.navigateTo({
						url: urlString
					})
					return
				}
			},
			async userInfo() {
				//console.log(11111);
				const token = uni.getStorageSync('token')
				//console.log(!token);
				if (!token) {
					uni.removeStorageSync('userinfo')
					uni.removeStorageSync('qw')
					uni.removeStorageSync('isLogin')
					uni.removeStorageSync('zhichengName')
					uni.removeStorageSync('qrUrl')
					uni.removeStorageSync('myTeam')
					uni.removeStorageSync('code')
					return
				}
				//if (!checkToken()) return
				// const r = uni.getStorageSync('userinfo')
				// if (r && r?.user) {
				// 	this.info = r.user
				// 	this.zhichengName = uni.getStorageSync('zhichengName') || ''
				// 	this.isLogin = uni.getStorageSync('isLogin') || true
				// 	return
				// }
				this.isLogin = uni.getStorageSync('isLogin') || true
				let res = await getInfo()
				if (res.code == 200) {
					//console.log(res,'res');
					uni.setStorageSync('userinfo', res)
					this.info = res.user
					this.zhichengName = uni.getStorageSync('zhichengName') || ''
					//uni.setStorageSync('isLogin', true) //已登录
				} else {
					uni.setStorageSync('isLogin', false) //未登录
				}
			},
			async goAction() {
				this.actionImg = require('@/static/img/No_follow.png')
				this.emptyText = '暂无待执行随访任务'
				if (this.navChoose != 0) {
					this.navChoose = 0
					this.clearPageStatus()
					await this.getTeam()
				}
			},
			async really() {
				this.actionImg = require('@/static/img/No_team@2x.png')
				this.emptyText = '暂无待评估随访任务'
				if (this.navChoose != 2) {
					this.navChoose = 2
					this.clearPageStatus()
					await this.getTeam()
				}
			}
		}
	}
</script>





<style lang="scss" scoped>
	@media (min-width:500px) {
		.index {
			margin-top: 20rpx;
			background: #F8F8F8;
			position: absolute;
			//	min-height: calc(100vh - 170px);
			min-height: 100vh;
			width: 375px;

			.docinfo {
				width: 702rpx;
				height: 168rpx;
				background: #FFFFFF;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				margin: 0 auto;
				margin-top: 20rpx;
				overflow: hidden;

				.docinfomain {
					width: 93%;
					margin: 0 auto;
					display: flex;
					justify-content: space-between;
					margin-top: 20rpx;

					.docinfomainr {
						width: 120rpx;
						height: 120rpx;
						border-radius: 50%;

						image {
							width: 100%;
							height: 100%;
							border-radius: 50%;
						}
					}

					.docinfomainl {
						.doctop {
							font-weight: 800;
							font-size: 48rpx;
							color: #212121;

							.zhicheng {
								font-weight: normal;
								font-size: 30rpx;
								margin-left: 10rpx;
							}
						}

						.docbottom {
							font-weight: 500;
							font-size: 30rpx;
							line-height: 60rpx;
							color: #999999;
						}
					}
				}
			}

			@media (min-width:500px) {
				.shoyetop {
					width: 375px;
					height: 90rpx;
					background: #EEFCFF;
					border-radius: 0rpx 0rpx 0rpx 0rpx;

					.shoyetopmain {
						width: 375px;
						margin: 0 auto;
						display: flex;

						.shoyetopl {
							width: 40rpx;
							height: 40rpx;
							margin-top: 25rpx;

							image {
								width: 100%;
								height: 100%;
							}
						}

						.shoyetopr {
							margin-left: 22rpx;
							font-weight: 500;
							font-size: 30rpx;
							color: #4DC0D9;
							line-height: 90rpx;
						}
					}
				}
			}

			@media (max-width:499px) {
				.shoyetop {
					width: 750rpx;
					height: 90rpx;
					background: #EEFCFF;
					border-radius: 0rpx 0rpx 0rpx 0rpx;

					.shoyetopmain {
						width: 95%;
						margin: 0 auto;
						display: flex;

						.shoyetopl {
							width: 40rpx;
							height: 40rpx;
							margin-top: 25rpx;

							image {
								width: 100%;
								height: 100%;
							}
						}

						.shoyetopr {
							margin-left: 22rpx;
							font-weight: 500;
							font-size: 30rpx;
							color: #4DC0D9;
							line-height: 90rpx;
						}
					}
				}
			}
		}
	}

	@media (max-width:499px) {
		.index {
			margin-top: 20rpx;
			background: #F8F8F8;
			position: absolute;
			//height: calc(100vh - 170rpx);
			min-height: 100vh;
			width: 100%;

			.job_box {
				margin-top: 40rpx;

				.job_nav {
					font-weight: bold;
					font-size: 36rpx;
					color: #999999;
					line-height: 38rpx;
					display: flex;
					margin-left: 24rpx;

					.black {
						color: #212121;
					}
				}

				.job_empty {
					min-height: 100vh;
					padding-top: 126rpx;
					padding-bottom: 210rpx;
					display: flex;
					flex-direction: column;
					//justify-content: center;
					align-items: center;

					.empty_text {
						font-weight: 500;
						font-size: 36rpx;
						color: #C7C7C7;
						line-height: 1.5;
						text-align: center;
					}
				}

				.job_content {
					background-color: #f8f8f8;
					margin: 24rpx 24rpx 8rpx 24rpx;
					border-radius: 20rpx;
					padding-bottom: 150rpx;

					.job_list {
						background-color: white;
						padding: 24rpx;
						font-family: PingFang SC, PingFang SC;
						font-size: 32rpx;
						color: #999999;
						line-height: 1.5;
						margin-bottom: 20rpx;
						border-radius: 20rpx;

						.job_title {
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 36rpx;
							color: #212121;
							line-height: 1.5;
							display: flex;
							align-items: center;

							.job_title_icon {
								padding: 0 8rpx;
								background: #4DC0D9;
								border-radius: 8rpx 8rpx 8rpx 8rpx;
								font-family: PingFang SC, PingFang SC;
								font-weight: 500;
								font-size: 26rpx;
								color: #FFFFFF;
								line-height: 36rpx;
								margin-right: 16rpx;
							}

							.yellow {
								background-color: #FF8D07;
							}
						}
					}

					.job_action {
						margin-top: 24rpx;
						display: flex;
						color: #4DC0D9;
						justify-content: flex-end;

						.job_left {
							margin-right: 48rpx;
						}

						.jobNav2 {}
					}
				}
			}


			.docinfo {
				width: 702rpx;
				height: 168rpx;
				background: #FFFFFF;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				margin: 0 auto;
				margin-top: 20rpx;
				overflow: hidden;

				.docinfomain {
					width: 93%;
					margin: 0 auto;
					display: flex;
					justify-content: space-between;
					margin-top: 20rpx;

					.docinfomainr {
						width: 120rpx;
						height: 120rpx;
						border-radius: 50%;

						image {
							width: 100%;
							height: 100%;
							border-radius: 50%;
						}
					}

					.docinfomainl {
						.doctop {
							font-weight: 800;
							font-size: 48rpx;
							color: #212121;

							.zhicheng {
								font-weight: normal;
								font-size: 30rpx;
								margin-left: 10rpx;
							}
						}

						.docbottom {
							font-weight: 500;
							font-size: 32rpx;
							line-height: 60rpx;
							color: #999999;
						}
					}
				}
			}

			.shoyetop {
				width: 750rpx;
				height: 90rpx;
				background: #EEFCFF;
				border-radius: 0rpx 0rpx 0rpx 0rpx;

				.shoyetopmain {
					width: 95%;
					margin: 0 auto;
					display: flex;

					.shoyetopl {
						width: 40rpx;
						height: 40rpx;
						margin-top: 25rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}

					.shoyetopr {
						margin-left: 22rpx;
						font-weight: 500;
						font-size: 30rpx;
						color: #4DC0D9;
						line-height: 90rpx;
					}
				}
			}
		}
	}
</style>